﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace Assist
{
	public static class ImpInsertUtil
	{
		public static void TagInsert(UIDocument m_uiDoc, Element elem)
		{
			SubTransaction subTransaction = new SubTransaction(m_uiDoc.Document);
			subTransaction.Start();
			try
			{
				BoundingBoxXYZ boundingBoxXYZ = elem.get_BoundingBox(m_uiDoc.ActiveView);
				XYZ pnt = new XYZ((boundingBoxXYZ.Min.X + boundingBoxXYZ.Max.X) / 2.0, (boundingBoxXYZ.Min.Y + boundingBoxXYZ.Max.Y) / 2.0, (boundingBoxXYZ.Min.Z + boundingBoxXYZ.Max.Z) / 2.0);
				IndependentTag independentTag = RevitVersionFuncs.NewTag(m_uiDoc.Document, m_uiDoc.ActiveView, new Reference(elem), false, 0, 0, pnt);
				subTransaction.Commit();
			}
			catch
			{
				subTransaction.RollBack();
			}
		}
	}
}
